package com.irain.pp.tool.api.transaction;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author iRain
 * @date 2017/12/7 19:52
 */
public class TransactionCenter {

    private static Set<TransactionSupport> serviceSet = ConcurrentHashMap.newKeySet();

    public static void register(TransactionSupport transactionService){
        serviceSet.add(transactionService);
    }

    public static void doAllBeginBefore(){
        serviceSet.forEach(TransactionSupport::doBeginBefore);
    }

    public static void doAllBeginAfter(){
        serviceSet.forEach(TransactionSupport::doBeginAfter);
    }

    public static void doAllCommitBefore(){
        serviceSet.forEach(TransactionSupport::doCommitBefore);
    }

    public static void doAllCommitAfter(){
        serviceSet.forEach(TransactionSupport::doCommitAfter);
    }

    public static void doAllRollBackBefore(){
        serviceSet.forEach(TransactionSupport::doRollbackBefore);
    }

    public static void doAllRollBackAfter(){
        serviceSet.forEach(TransactionSupport::doRollbackAfter);
    }
}
